

#ifndef MouseAndCat_Master_h
#define MouseAndCat_Master_h

#include <iostream>
#include <math.h>

#include "Events.h"
//#include "KeyboardHook.h"
#include "Message.h"
#include "Messenger.h"
//#include "MouseHook.h"
#include "MncPoint.h"
#include "TransparentForm.h"
#include "Types.h"

class Master
{
public:
    
    enum XEntry
    {
        Left = 1,
        Right = 2
    };

    explicit Master(std::string remote_ip, int port);
    ~Master();
    
    void Start();
    void Stop();
	void MouseEventOccured(abyte event_type, abyte move_type, uint timestamp, short x, short y, short wheelDelta);
	void KeyboardEventOccured(abyte event_type, uint timestamp,  abyte key);

private:
    
    Messenger* messenger_;
    TransparentForm transparentForm_;
    bool controlling_;
    bool debug_key1_down_;
    bool debug_key2_down_;
	short screen_width_;
    short screen_height_;
	XEntry reentryX_;
    uint32_t message_index;
    
    bool StartControlling(uint timestamp, short x, short y);
    void StopControlling(short y);
    void HideTransparentForm();
    void HideInvisibleWindow();
    void MouseLeaveCallback(short y);
    void SendMessage(Message, uint timestamp, MncPoint position, short wheelDelta);
    void SendMessage(Message, uint timestamp, abyte vkKey);
    
};

#endif
